﻿Ext.define('App.desktop.GridWindow', {
    extend: 'Ext.Window',
    requires: ['App.desktop.GridView'],
    closable: true,
    closeAction: 'hide',
    height: 500,
    width: 800,
    border: false,
    layout: 'fit',
    constrain: true,

    initComponent: function () {

        var me = this;

        if (me.attribute == null) {

            me.title = me.entity.Name;
        }
        else {

            me.title = me.entity.Name + '. ' + me.attribute.Name + '[' + me.child.Name + ']';
        }

        me.view =
        {
            xtype: 'GridView',
            itemId: 'gridView',
            entity: me.entity,
            attribute: me.attribute,
            child: me.child,
            identifiers: Ext.encode(Ext.decode(me.identifiers)) // To generate a valid JSON
        };

        me.items = [me.view];

        me.callParent();
    },

    listeners:
    {
        afterrender: function () {
            this.loadGrid();
        }
    },

    loadGrid: function () {

        this.getComponent('gridView').loadGrid();
    }
});